<span page-title>{{ 'Content Hosts' | translate }}</span>

<div data-extend-template="layouts/table-with-header.html">

  <div data-block="header">
    <h2 translate>Content Hosts</h2>
  </div>

  <div data-block="list-actions">
    <a href="/hosts/content_hosts.csv?{{csvQuery()}}" class="btn btn-default" target="_self">
      <span translate>Export</span>
    </a>
    <a class="btn btn-default" href="/hosts/register" ng-show="permitted('create_hosts')" translate>
      Register Content Host
    </a>

    <span select-action-dropdown>
      <ul class="dropdown-menu dropdown-menu-right" uib-dropdown-menu role="menu" aria-labelledby="split-button">
        <li role="menuitem" ng-show="permitted('edit_hosts')" ng-class="{disabled: table.numSelected === 0}">
          <a ng-click="openHostCollectionsModal()" disable-link="table.numSelected === 0" translate>Change Host Collections</a>
        </li>

        <li bst-feature-flag="remote_actions" role="menuitem" ng-show="permitted('edit_hosts')" ng-class="{disabled: table.numSelected === 0}">
          <a ng-click="openPackagesModal()" disable-link="table.numSelected === 0" translate>Manage Packages</a>
        </li>

        <li bst-feature-flag="remote_actions" role="menuitem" ng-show="permitted('edit_hosts')" ng-class="{disabled: table.numSelected === 0}">
          <a ng-click="openErrataModal()" disable-link="table.numSelected === 0" translate>Manage Errata</a>
        </li>

        <li role="menuitem" ng-show="permitted('edit_hosts')" ng-class="{disabled: table.numSelected === 0}">
          <a ng-click="openEnvironmentModal()" disable-link="table.numSelected === 0" translate>Change Lifecycle Environment</a>
        </li>

        <li role="menuitem" ng-show="permitted('edit_hosts')" ng-class="{disabled: table.numSelected === 0}">
          <a ng-click="openSetReleaseVersionModal()" disable-link="table.numSelected === 0" translate>Set Release Version</a>
        </li>

        <li role="menuitem" ng-show="permitted('edit_hosts') && !simpleContentAccessEnabled" ng-class="{disabled: table.numSelected === 0}">
          <a ng-click="openSubscriptionsModal()" disable-link="table.numSelected === 0" translate>Manage Subscriptions</a>
        </li>

        <li role="menuitem" ng-show="permitted('edit_hosts')" ng-class="{disabled: table.numSelected === 0}">
          <a ng-click="openRepositorySetsModal()" disable-link="table.numSelected === 0" translate>Manage Repository Sets</a>
        </li>

        <li role="menuitem" ng-show="permitted('edit_hosts')" ng-class="{disabled: table.numSelected === 0}">
          <a ng-click="openModuleStreamsModal()" disable-link="table.numSelected === 0" translate>Manage Module Streams</a>
        </li>

        <li role="menuitem" ng-show="permitted('edit_hosts')" ng-class="{disabled: table.numSelected === 0}">
          <a ng-click="openSystemPurposeModal()" disable-link="table.numSelected === 0" translate>Manage System Purpose</a>
        </li>

        <li role="menuitem" ng-show="permitted('edit_hosts')" ng-class="{disabled: table.numSelected === 0}">
          <a ng-click="openTracesModal()" disable-link="table.numSelected === 0" translate>Manage Host Traces</a>
        </li>

        <li class="divider"></li>

        <li role="menuitem" ng-show="permitted('destroy_hosts')" ng-class="{disabled: table.numSelected === 0}">
          <a ng-click="openModal()" disable-link="table.numSelected === 0" translate>Delete Hosts</a>
          <span bst-modal="performDestroyHosts()" template-url="content-hosts/bulk/views/content-hosts-bulk-destroy-modal.html"></span>
        </li>
      </ul>
    </span>
  </div>

  <span data-block="no-rows-message" translate>
    You currently don't have any Content Hosts, you can register one by clicking the button on the right and following the instructions.
  </span>

  <span data-block="no-search-results-message" translate>
    Your search returned zero Content Hosts.
  </span>

  <div data-block="table">
    <table class="table table-striped table-bordered" ng-class="{'table-mask': table.working}">
      <thead>
        <tr bst-table-head row-select>
          <th bst-table-column="name" sortable><span translate>Name</span></th>
          <th bst-table-column="subscription_status" ng-hide="simpleContentAccessEnabled" sortable>
            {{ 'Subscription Status' | translate }}
          </th>
          <th bst-table-column="status">
            <span translate>Installable Updates</span>
          </th>
          <th bst-table-column="os" sortable><span translate>OS</span></th>
          <th bst-table-column="lifecycle_environment" sortable><span sortable translate>Lifecycle Environment</span></th>
          <th bst-table-column="content_view" sortable><span translate>Content View</span></th>
          <th bst-table-column="registered_at" sortable><span translate>Registered</span></th>
          <th bst-table-column="last_checkin" sortable><span translate>Last Checkin</span></th>
        </tr>
      </thead>

      <div data-extend-template="layouts/select-all-results.html"></div>

      <tbody>
        <tr bst-table-row ng-repeat="host in table.rows" row-select="host"
            ng-controller="ContentHostStatusController">
          <td bst-table-cell>
            <a ui-sref="content-host.info({hostId: host.id})">
              {{ host.name }}
            </a>
          </td>
          <td bst-table-cell ng-hide="simpleContentAccessEnabled">
            <span ng-class="table.getHostStatusIcon(host.subscription_global_status)">
            </span>
          </td>
          <td>
            <a ui-sref="content-host.errata.index({hostId: host.id})">
              <span class="aligned-errata-count" errata-counts="host.content_facet_attributes.errata_counts"></span>
            </a>

            <a ui-sref="content-host.packages.applicable({hostId: host.id})">
            <span class="aligned-errata-count">
              <span class="errata-count"
                 ng-class="{black: !host.content_facet_attributes.upgradable_package_count,
                            green: host.content_facet_attributes.upgradable_package_count > 0}">
                <span>
                  {{ host.content_facet_attributes.upgradable_package_count || 0 }}
                </span>
                <i class="fa fa-cube inline-icon" title="{{ 'Package Updates' | translate }}"></i>
              </span>
            </span>
            </a>
          </td>
          <td bst-table-cell>{{ host.operatingsystem_name }}</td>
          <td bst-table-cell>{{ host.content_facet_attributes.lifecycle_environment.name }}</td>
          <td bst-table-cell>{{ host.content_facet_attributes.content_view.name || "" }}</td>
          <td bst-table-cell><long-date-time date="host.subscription_facet_attributes.registered_at" default="'Never registered' | translate" /></td>
          <td bst-table-cell><long-date-time date="host.subscription_facet_attributes.last_checkin" default="'Never checked in' | translate" /></td>
        </tr>
      </tbody>
    </table>
  </div>
</div>
